# 此函数用于光纤信号的衰减
# 传入参数：
#   signal:信号
#   alpha:衰减
#
# 输出参数：
#   sig：衰减后的信号，时域
from numpy import exp
from numpy.fft import fft, fftshift, ifftshift, ifft
import numpy as np


def signal_attenuation(signal, Signal, Fiber_para, PMD_para):
    # [1/km]
    alpha_km = Fiber_para["alpha_km"]
    polar_n = Signal["polarization"]
    # [km]
    deltaz = Fiber_para["step_size"]
    PMD = PMD_para["PMD"]
    steptype = Fiber_para['ssfm_type']

    if polar_n == 1:

        data = signal
        data_fft = fftshift(fft(data))
        # # 衰减
        data_fft = data_fft * exp((-alpha_km/2)*(deltaz/2))
        data_t = ifft(ifftshift(data_fft))
        sig = data_t
    return sig
